//
//  HEMyOrderPayPersonCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2021/5/8.
//  Copyright © 2021 honglutec. All rights reserved.
//

#import "HEMyOrderPayPersonCell.h"

@interface HEMyOrderPayPersonCell ()

@property (nonatomic, strong) UILabel *titleLb;

@property (nonatomic, strong) UIImageView *logoImgView;

@property (nonatomic, strong) UILabel *nameLb;
@property (nonatomic, strong) UILabel *detialsLb;
@property (nonatomic, strong) UIImageView *consulting;

@end

@implementation HEMyOrderPayPersonCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
     if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
         self.selectionStyle = UITableViewCellSelectionStyleNone;
         [self initUI];
     }
     return self;;
}

- (void)initUI {
    
    _titleLb = [UILabel new];
    _titleLb.font = DYBlodFont(18);
    _titleLb.text = @"代付人信息";
    _titleLb.textColor = CNavLightBlackColor;
    [self.contentView addSubview:_titleLb];

    UIView *headLine = [UIView new];
    headLine.backgroundColor = CSplitLineColor;
    [self.contentView addSubview:headLine];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(10);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-10);
    }];
    [_titleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
  
    [headLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(10);
        make.height.mas_offset(1);
        make.left.equalTo(_titleLb);
        make.right.equalTo(self.contentView).mas_offset(-15);
    }];
    
    
    // 头像
    _logoImgView = [UIImageView new];
    _logoImgView.contentMode = UIViewContentModeScaleAspectFill;
    _logoImgView.image = IMAGE_NAMED(@"address_location");
    [self.contentView addSubview:_logoImgView];

    _nameLb = [UILabel new];
    _nameLb.text = @"-";
    _nameLb.font = DYFont(16);
    [self.contentView addSubview:_nameLb];
    
    _detialsLb = [UILabel new];
    _detialsLb.font = DYFont(16);
    _detialsLb.textColor = CNavLightBlackColor;
    _detialsLb.text = @"-";
    _detialsLb.numberOfLines = 0;
     [self.contentView addSubview:_detialsLb];

    _consulting = [UIImageView new];
    _consulting.contentMode = UIViewContentModeScaleAspectFill;
    _consulting.image = IMAGE_NAMED(@"call_main");
    _consulting.userInteractionEnabled = YES;
     [self.contentView addSubview:_consulting];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(callPhoneClick)];
    [_consulting addGestureRecognizer:tap];
    
    
    [_logoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headLine.mas_bottom).mas_offset(15);
        make.width.height.mas_offset(55);
        make.left.equalTo(_titleLb);
    }];
    [_logoImgView hg_setAllCornerWithCornerRadius:55 / 2.0f];

    [_nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headLine.mas_bottom).mas_offset(15);
        make.left.equalTo(_logoImgView.mas_right).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
    }];
    
    [_detialsLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nameLb.mas_bottom).mas_offset(15);
        make.left.equalTo(_nameLb.mas_left);
        make.right.equalTo(_consulting.mas_left).mas_offset(-10);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
     }];

    [_consulting mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_logoImgView);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.width.height.mas_offset(25);
    }];
}

- (void)callPhoneClick {
    [DYTools callPhone: self.formModel.od_details.KdoctorInfo.pay_agent_info.phone];
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
    
    HEOldPersonInfo *model = self.formModel.od_details.KdoctorInfo.pay_agent_info;

    if (model == nil) {
        return;
    }
    
    [_logoImgView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:IMAGE_NAMED(@"defualt_icon")];
    _nameLb.text = model.KnameRel;
    _detialsLb.text = model.phone;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
